/**
 * 
 */
package com.locus.tools.location;

import android.graphics.*;
import android.location.Location;
import com.google.android.maps.Overlay;
import com.google.android.maps.Point;

/*
 * TODO:: edit so that instead of a initializing and using a "paint", we can initialize with arbitrary icons/graphics
 * 
 */
/**
 * A Generic Overlay type for GPS locations.
 * 
 * @author jfredett
 *
 */
public class LocationOverlay extends Overlay {
	private Location locale;
	private Paint paintColor = new Paint();
	
	public LocationOverlay(Location l) { locale = l; } 
	public LocationOverlay(Location l, Paint p) { locale = l; paintColor = p;}
	
	/**
	 * draws your locations w/ a message beneath it to the canvas.
	 */
	public void draw(Canvas canvas, PixelCalculator pc, boolean b) {
		// draw the main overlay stuff
		super.draw(canvas, pc, b);
		
		// now we draw our stuff
		int[] xycoords = new int[2];
		Point locpoint = new Point( toMicrodegrees(locale.getLatitude())
						  	      , toMicrodegrees(locale.getLongitude())
						  	      );
		pc.getPointXY(locpoint, xycoords);
		canvas.drawCircle(xycoords[0], xycoords[1], 9, paintColor);
		canvas.drawText("You are here", xycoords[0], xycoords[1]-10, paintColor);
		
		/* TODO :: edit so the message draw comes from construction time...
		 * currently this will display "You are here" for every contact used."
		 */
	}

	/**
	 * Converts a degrees to microdegrees rounded to the nearest microdegree.
	 * @param degs
	 * @return 
	 */
	private int toMicrodegrees(double degs) {
		return ((int) (degs * 1000000));
	}
	
	
	
	
}
